package com.zbkj.admin.controller.platform.assistant;

import com.zbkj.admin.controller.platform.assistant.service.AssistantGroupService;
import com.zbkj.common.model.assistant.AssistantGroup;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.assistant.model.request.AssistantGroupRequest;
import com.zbkj.service.assistant.model.request.AssistantGroupSearchRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 客服分组表 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/platform/assistant/group")
@Api(tags = "客服-分组") //配合swagger使用
public class AssistantGroupController {

    @Autowired
    private AssistantGroupService assistantGroupService;

    @ApiOperation(value = "列表") //配合swagger使用
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<List<AssistantGroup>>  getList(@Validated AssistantGroupSearchRequest request) {
        List<AssistantGroup> list = assistantGroupService.getList(request);
        return CommonResult.success(list);
    }

    /**
     * 修改客服分组表
     * @param assistantGroupRequest 修改参数
     * @author zhuwy
     * @since 2025-06-18
     */
    @ApiOperation(value = "修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public CommonResult<String> update(@RequestBody @Validated AssistantGroupRequest assistantGroupRequest) {
        AssistantGroup assistantGroup = new AssistantGroup();
        BeanUtils.copyProperties(assistantGroupRequest, assistantGroup);

        if(assistantGroupService.updateById(assistantGroup)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 查询客服分组表信息
     * @param id Integer
     * @author zhuwy
     * @since 2025-06-18
     */
    @ApiOperation(value = "详情")
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public CommonResult<AssistantGroup> info(@RequestParam(value = "id") Integer id) {
        AssistantGroup assistantGroup = assistantGroupService.getById(id);
        return CommonResult.success(assistantGroup);
    }
}



